/**
 * 
 */
package com.paypal.melearning.ui.component;

import java.util.List;

import com.paypal.melearning.domain.Board;
import com.paypal.melearning.domain.Pin;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.VerticalLayout;

/**
 * @author prakrishnan
 * 
 */
public class BoardComponent extends VerticalLayout {

	private List<Board> curBoards;

	public BoardComponent(List<Board> boards) {
		this.curBoards = boards;
	}

	@Override
	public void attach() {
		super.attach(); // Must call.
		setSpacing(true);
		getWindow().setScrollable(true);

		final GridLayout grid = new GridLayout(5, 1);
		grid.setWidth("100%");
		// grid.setHeight("100%");

		addComponent(grid);

		VerticalLayout layOut1 = new VerticalLayout();
		grid.addComponent(layOut1);
		VerticalLayout layOut2 = new VerticalLayout();
		grid.addComponent(layOut2);
		VerticalLayout layOut3 = new VerticalLayout();
		grid.addComponent(layOut3);
		VerticalLayout layOut4 = new VerticalLayout();
		grid.addComponent(layOut4);
		VerticalLayout layOut5 = new VerticalLayout();
		grid.addComponent(layOut5);

		List<Pin> curPins = curBoards.get(0).getPins();
		for (int i = 0; i < curPins.size(); i++) {
			if (i % 5 == 0) {
				layOut1.addComponent(new PinComponent(curPins.get(i)));
			} else if (i % 5 == 1) {
				layOut2.addComponent(new PinComponent(curPins.get(i)));
			} else if (i % 5 == 2) {
				layOut3.addComponent(new PinComponent(curPins.get(i)));
			} else if (i % 5 == 3) {
				layOut4.addComponent(new PinComponent(curPins.get(i)));
			} else if (i % 5 == 4) {
				layOut5.addComponent(new PinComponent(curPins.get(i)));
			}
		}

	}
}
